/*
 * @Description: 
 * @Author: 韩双双
 * @Date: 2021-04-20 20:26:41
 * @LastEditTime: 2021-04-26 15:05:27
 * @LastEditors: 韩双双
 */

import { RequestConfig } from 'umi';
import { message } from 'antd';

//在跟组件注入store
import StoreContext from '@/context/storeContext'
import store from '@/store';
import React from 'React'
// import StoreContext from '@/context/storeContext';


let baseUrl = 'https://api.blog.wipi.tech'
export const request: RequestConfig = {
  timeout: 5000,
  errorConfig: {},
  middlewares: [],
  requestInterceptors: [(url, options) => {
    return {
      url: baseUrl+url,
      options: { ...options, interceptors: true },
    };
  },],
  responseInterceptors: [response => {
    const codeMaps:{[key:string]:string} = {
      500: '服务器有误',
      502: '网关错误。',
      503: '服务不可用，服务器暂时过载或维护。',
      504: '网关超时。',
      400: '请求错误',
      404: '请求资源不存在',
      403: '请求信息携带有误',
      401: '鉴权失败'
    };
    // console.log('response...',response)
    if(response.status !== 200){
        message.error(codeMaps[response.status]);
    }
    return response;
  }],
};

export function rootContainer(container:any){
    return  React.createElement(StoreContext.Provider, {value:store}, container)
}